const path = require('path');

//@SpringBoot
class Application {

	//@Autowired
	zcFtpService;

	async main(){

		try{


			this.zcFtpService.safeInvoke(async ftp => {

				console.log("ftp 主机 登陆成功");


				console.log("显示根目录 /");

				const datas = await ftp.list("/");
				const rootDirName = datas[0].name;
				console.log(`根目录名称:${rootDirName}`)

				ftp.cwd(rootDirName+"/ftptest")
				console.log("进入courware/ftptest目录成功");
				const data2s = await ftp.list("");
				console.log(data2s)

				const uploadDir = "uploadTestDir78";

				await ftp.mkdirAndGoto(uploadDir)
				console.log(`创建上传目录${uploadDir}成功`);

				const uploadInfo = await ftp.put(path.join(__dirname,'uploadTestA.txt'),"uploadTestA.txt")
				console.log("文件上传成功",uploadInfo);

				ftp.cwd("../")

				await ftp.rmdir(uploadDir)

				console.log("删除上传目录成功");

			})

		}catch(e){
			 await this.zcFtpService.close();
			console.log(e)
		}
		

	}

}

 module.exports = { Application }